package com.xhd.base.session;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Hashtable;

import com.xhd.exception.SystemException;

public abstract class SessionStore {
	  protected abstract boolean load(Session parambaseSession);

	  protected abstract boolean remove(String paramString);

	  protected abstract boolean save(Session paramSession);
	  protected abstract boolean save(Session parambaseSession, boolean paramBoolean);

	  protected abstract Hashtable loadAll()
	    throws SystemException;

	  protected abstract boolean saveAttributes(Session localSession, String paramString);

	  protected boolean load(InputStream paramInputStream, Session paramSession)
	    throws IOException, ClassNotFoundException
	  {
	    if (paramInputStream == null)
	      return false;
	    ObjectInputStream localObjectInputStream = new ObjectInputStream(paramInputStream);
	    int i = localObjectInputStream.readInt();
	    int j = localObjectInputStream.readInt();
	    for (int k = 0; k < j; ++k)
	    {
	      String str = localObjectInputStream.readUTF();
	      Object localObject = null;
	      try
	      {
	        localObject = localObjectInputStream.readObject();
	      }
	      catch (Exception localException)
	      {
	      }
	      if ((str == null) || (localObject == null))
	        continue;
	      paramSession.setAttribute(str, localObject);
	    }
	   int   k = localObjectInputStream.readInt();
	    return (i == k);
	  }

	  protected boolean save(OutputStream paramOutputStream, Session paramSession)
	    throws IOException
	  {
	    ObjectOutputStream localObjectOutputStream = new ObjectOutputStream(paramOutputStream);
	    int i = 1;
	    int j = paramSession.getSessionData().size();
	    localObjectOutputStream.writeInt(i);
	    localObjectOutputStream.writeInt(j);
	    Enumeration localEnumeration = paramSession.getSessionData().keys();
	    while (localEnumeration.hasMoreElements())
	    {
	      String str = (String)localEnumeration.nextElement();
	      Object localObject = paramSession.getAttribute(str);
	      localObjectOutputStream.writeUTF(str);
	      localObjectOutputStream.writeObject(localObject);
	    }
	    localObjectOutputStream.writeInt(i);
	    localObjectOutputStream.flush();
	    return true;
	  }

	
	  
	

}
